**************************************************************
* ELECTRICITY SPILOVERS PROJECT
*  SURVEY BALANCE TABLES AND REGRESSIONS
**************************************************************
set more off
frame create survey
frame change survey

***************************************************
*TABLE C.1 - SURVEY PARTICIPATION ATTRITION AND BALANCE 
***************************************************
use $data_main\survey_results_20170728.dta, clear

*Merging historical water data	
merge m:1 HHID using $data_main\BaselineWater_20171018.dta
	keep if _merge==3
	drop _merge

*Merge historical summer and annual electricity use data
merge m:1 HHID using $data_main\elecbilling_controls_20170919.dta
	keep if _merge==3
	drop _merge
	
merge m:1 HHID using $data_main\PoolAssessorData_20170622_destring.dta
	drop if _merge==2
	drop _merge

label var w_use_annual "Baseline Annual Water Use"
label var w_use_summer "Baseline Summer Water Use"
label var w_use_winter "Baseline Winter Water Use"
label var elec_use_annual "Baseline Annual Electricity Use"
label var elec_use_summer "Baseline Summer Electricity Use"
label var elec_use_winter "Baseline Winter Electricity Use"
drop if elec_use_summer==.
drop if flag_outlier==1

***
*Response Balance
eststo clear
*Column 1: WS Group Response and Pre-Treatment Use
eststo: reg complete w_use_annual w_use_summer w_use_winter elec_use_annual elec_use_summer elec_use_winter  if ws==1, vce(robust)
	estadd local sam "WS"		
	est store A

*Column 2: Control Group Response and Pre-Treatment Use
eststo: reg complete w_use_annual w_use_summer w_use_winter elec_use_annual elec_use_summer elec_use_winter  if ws==0, vce(robust)
	estadd local sam "Control"
	est store B

*Column 3: Control Group Response and Pre-Treatment Use
eststo: reg ws w_use_annual w_use_summer w_use_winter elec_use_annual elec_use_summer elec_use_winter  if complete==1, vce(robust)
	estadd local sam "Complete Survey"
	est store C

esttab A B C using $tables\survey_balance_$outputdate.tex, replace label ///
    booktabs b(a2) nonumber ///
    starlevels(* 0.10 ** 0.05 *** 0.01) ///
	title(Survey Participation: Attrition and Balance Tests \label{survey1})  ///
	cells(b(fmt(6) star) se(fmt(6) par)) ///
	note(\footnotesize Notes: Columns (1) and (2) report results from a linear ///
	     probability model regressing survey completion on ///
		 baseline water use. The sample in column (1) ///
		 is comprised only of households assigned to the WaterSmart treatment, ///
		 and the sample in column (2) is comprised of households assigned ///
		 to control.  Column (3) reports results from a linear ///
		 probability model regressing treatment ///
		 on baseline water use for all ///
		 households.  The sample in all columns is limited to those households ///
		 for which we observe pre-treatment water and electricity use data. ///
		 Standard errors are robust to heteroskedasticity. ///
		 *, **, *** denote significance at the 10\%, 5\%, and 1\%level.) ///
	scalars("sam Sample") ///
	 mlabels((1) (2) (3)) collabels(none) 	

		
****************************************************************
*TABLE C.2: SURVEY ANALYSIS OLS REGRESSION
*******************************************************************
eststo clear

eststo: reg enrgy_act_cons ws w_use_winter w_use_summer w_use_annual elec_use_summer elec_use_annual elec_use_winter, vce(robust)
	sum enrgy_act_cons if e(sample) & ws==0
	scalar survey_c = r(mean)
	sum enrgy_act_cons if e(sample) & ws==1
	scalar survey_ws = r(mean)
		estadd scalar m_c = scalar(survey_c) 
		estadd scalar m_t = scalar(survey_ws)				
	est store A
	
eststo: reg enrgy_act_cool ws w_use_winter w_use_summer w_use_annual elec_use_summer elec_use_annual elec_use_winter, vce(robust)
	sum enrgy_act_cool if e(sample) & ws==0
	scalar survey2_c = r(mean)
	sum enrgy_act_cool if e(sample) & ws==1
	scalar survey2_ws = r(mean)
		estadd scalar m_c = scalar(survey2_c) 
		estadd scalar m_t = scalar(survey2_ws)				
	est store B
			
eststo: reg enrgy_act_therm ws w_use_winter w_use_summer w_use_annual elec_use_summer elec_use_annual elec_use_winter, vce(robust)	
	sum enrgy_act_therm if e(sample) & ws==0
	scalar survey3_c = r(mean)
	sum enrgy_act_therm if e(sample) & ws==1
	scalar survey3_ws = r(mean)
		estadd scalar m_c = scalar(survey3_c) 
		estadd scalar m_t = scalar(survey3_ws)				
	est store C
			
eststo: reg enrgy_act_airdry ws w_use_winter w_use_summer w_use_annual elec_use_summer elec_use_annual elec_use_winter, vce(robust)	
	sum enrgy_act_airdry if e(sample) & ws==0
	scalar survey4_c = r(mean)
	sum enrgy_act_airdry if e(sample) & ws==1
	scalar survey4_ws = r(mean)
		estadd scalar m_c = scalar(survey4_c) 
		estadd scalar m_t = scalar(survey4_ws)				
	est store D
	
	eststo: reg wtr_act_dw ws w_use_winter w_use_summer w_use_annual elec_use_summer elec_use_annual elec_use_winter, vce(robust)	
	sum wtr_act_dw if e(sample) & ws==0
	scalar survey5_c = r(mean)
	sum wtr_act_dw if e(sample) & ws==1
	scalar survey5_ws = r(mean)
		estadd scalar m_c = scalar(survey5_c) 
		estadd scalar m_t = scalar(survey5_ws)				
	est store E
			
eststo: reg wtr_act_cw  ws w_use_winter w_use_summer w_use_annual elec_use_summer elec_use_annual elec_use_winter, vce(robust)	
	sum wtr_act_cw  if e(sample) & ws==0
	scalar survey6_c = r(mean)
	sum wtr_act_cw  if e(sample) & ws==1
	scalar survey6_ws = r(mean)
		estadd scalar m_c = scalar(survey6_c) 
		estadd scalar m_t = scalar(survey6_ws)				
	est store F
			

esttab A B C D E F using $tables\surveyregs_$outputdate.tex, replace label ///
    booktabs b(a2) nonumber ///
	drop(w_use_winter w_use_summer w_use_annual elec_use_summer elec_use_annual elec_use_winter) ///
    starlevels(* 0.10 ** 0.05 *** 0.01) ///
	title(Survey Responses Across Control and Treatment (Dependent Variable: ///
		  Survey Response) \label{surveyregs1}) ///
	cells(b(fmt(6) star) se(fmt(6) par)) ///
	note(Notes: The table reports  results from an OLS ///
	     regression of the response to each survey question on assignment to the treatment. ///
		Controls include mean monthly water and energy use in the summer, winter and year ///
		preceding treatment. Standard errors are ///
		clustered at the household. *, **, *** denote significance at the ///
		10\%, 5\%, and 1\%level.) ///
	scalars("m_c Mean Response Control Group" "m_t Mean Response WS Treatment") ///  					
	
frame change data_main
frame drop survey 